package simple.engine.world;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

import simple.engine.drawable.SimpleObject;
import simple.engine.managers.ScreenManager;
import android.opengl.GLU;

public class SimpleScene {
	
	private SimpleCamera mCamera;
	private ArrayList<SimpleObject> mArrayList;
	
	public SimpleScene()
	{
		mCamera = new SimpleCamera(0,0,0);
		mArrayList = new ArrayList<SimpleObject>();
	}	
	
	public SimpleCamera getCamera()
	{
		return mCamera;
	}
	
	public void drawScene(GL10 gl)
	{
		GLU.gluLookAt(gl, mCamera.getX(), mCamera.getY(), mCamera.getZ() / ScreenManager.getScale(), mCamera.getX(), mCamera.getY(), 0.0f, 0f, 1f, 0f);
		for(int i=0 ; i<mArrayList.size(); i++) mArrayList.get(i).draw(gl);
	}
	
	public SimpleObject addChild(SimpleObject child)
	{
		mArrayList.add(child);
		return child;
	}
	
	public void removeChild(SimpleObject child)
	{
		mArrayList.remove(child);
	}
	
	public SimpleObject getChild(String id)
	{
		for(int i=0; i<mArrayList.size(); i++) 
		{
			if(mArrayList.get(i).getID() == id) return mArrayList.get(i);
		}
		return null;
	}
	
	public SimpleObject getClickedChild(float x, float y)
	{
		/*for(int i=mArrayList.size() -1 ; i>=0; i--)
		{
			Vector2f pos = mArrayList.get(i).getPosition();
			Vector2f size = mArrayList.get(i).getSize();
			
			if(pos.getX() < x && x < pos.getX() + size.getX() && pos.getY() - size.getY() < y &&  y < pos.getY()) return mArrayList.get(i);
		}*/
		
		return null;
	}
	
	public void destroy()
	{
		mArrayList.clear();
	}
	
	
	
}
